#include"Text.h"
CText::CText()
{
	text=NULL;
	//mario=NULL;
	load=NULL;
	save=NULL;
	world=NULL;
	time=NULL;
	player=NULL;
	_player=NULL;
	resume=NULL;
	info=NULL;
	image=NULL;
	gameover=NULL;
}
CText::~CText()
{
	if(text!=NULL) delete text;
	//if(mario!=NULL) mario->Release();
	//if(world!=NULL) world->Release();
	//if(time!=NULL) time->Release();
	if(save!=NULL) save->Release();
	if(load!=NULL) load->Release();
	if(resume!=NULL) resume->Release();
	if(player!=NULL) player->Release();
	if(_player!=NULL) _player->Release();
	if(info!=NULL) info->Release();
	if(image!=NULL) image->Release();
	if(gameover!=NULL) gameover->Release();
}
LPDIRECT3DTEXTURE9 CText::GetImage(LPDIRECT3DDEVICE9 d3ddv, LPWSTR filename)
{
	D3DXIMAGE_INFO info;
	LPDIRECT3DTEXTURE9 image;
	HRESULT result= D3DXGetImageInfoFromFile(filename,&info);
	if(result!=D3D_OK) return NULL;
	D3DXCreateTextureFromFileEx(d3ddv,filename,info.Width,info.Height,1,D3DPOOL_DEFAULT,D3DFMT_UNKNOWN,D3DPOOL_DEFAULT,D3DX_DEFAULT,D3DX_DEFAULT,D3DCOLOR_XRGB(0,0,0),&info,NULL,&image);
	return image;
}
void CText::LoadResources(LPDIRECT3DDEVICE9 d3ddv)
{
	//image=GetImage(d3ddv,L"1player.png");
	for(int i=0;i<9;i++)
	{
		switch(i)
		{
		case 0:
		case 1:
		case 2:info=GetImage(d3ddv,L"Image\\Info.png");break;
		case 3:load=GetImage(d3ddv,L"Image\\loadgame.png");break;
		case 4:player=GetImage(d3ddv,L"Image\\1player.png");break;
		case 5:break;
		case 6:resume=GetImage(d3ddv,L"Image\\resumegame.png");break;
		case 7:save=GetImage(d3ddv,L"Image\\savegame.png");break;
		case 8:exit=GetImage(d3ddv,L"Image\\exitgame.png");break;
		}
	}
	gameover=GetImage(d3ddv,L"Image\\gameover.png");
}
void CText::RenderIntro(LPD3DXSPRITE sprite)
{
	text= new CSprite(true,80,0,90,30,0,0,0);
	text->Render(sprite,info,250,200);
}
void CText::RenderGameOver(LPD3DXSPRITE sprite)
{
	text= new CSprite(true,0,0,150,30,0,0,0);
	text->Render(sprite,gameover,250,250);
}
void CText::Render(LPDIRECT3DDEVICE9 d3ddv,LPD3DXSPRITE sprite,bool isMenu, int stage)
{
	if(isMenu==true) 
	{
		if(stage!=0) n=8;
		else n=6;
	}
	else n=3;
	if(stage!=0)
	for(int i=0;i<n;i++)
	{	
		switch(i)
	{
		case 0: 
			{
				//image=GetImage(d3ddv,L"Info.png");
				text= new CSprite(true,0,0,80,30,0,0,0);
				x=20;
				y=0;
				text->Render(sprite,info,x,y);
			}break;
		case 1:
			{
				//image=GetImage(d3ddv,L"Info.png");
				text= new CSprite(true,80,0,90,30,0,0,0);
				x=300;
				y=0;
				text->Render(sprite,info,x,y);
			}break;
		case 2:
			{
				//image=GetImage(d3ddv,L"Info.png");
				text= new CSprite(true,170,0,100,30,0,0,0);
				x=500;
				y=0;
				text->Render(sprite,info,x,y);
			}break;
		case 3:
			{
				//image=GetImage(d3ddv,L"loadgame.png");
				
				text= new CSprite(true,0,0,200,20,0,0,0);
				x=240;
				y=290;
				
				text->Render(sprite,load,x,y);
			}break;
		case 4:
			{
				//image=GetImage(d3ddv,L"1player.png");
				text= new CSprite(true,0,0,200,20,0,0,0);
				x=240;
				y=200;
				text->Render(sprite,player,x,y);
			}break;
		case 5:
			{
				//image=GetImage(d3ddv,L"resume.png");
				text= new CSprite(true,0,0,200,20,0,0,0);
				x=240;
				y=230;
				text->Render(sprite,resume,x,y);
			}break;
		case 6:
			{
				//image=GetImage(d3ddv,L"save.png");
				text= new CSprite(true,0,0,200,20,0,0,0);
				x=240;
				y=260;
				text->Render(sprite,save,x,y);
			}break;
		case 7:
			{
				//image=GetImage(d3ddv,L".png");
				text= new CSprite(true,0,0,200,20,0,0,0);
				x=240;
				y=320;
				text->Render(sprite,exit,x,y);
			}break;
		
	}
		
	}
	else for(int i=0;i<n;i++)
	{	
		switch(i)
	{
		case 0: 
			{
				//image=GetImage(d3ddv,L"Info.png");
				text= new CSprite(true,0,0,80,30,0,0,0);
				x=20;
				y=0;
				text->Render(sprite,info,x,y);
			}break;
		case 1:
			{
				//image=GetImage(d3ddv,L"Info.png");
				text= new CSprite(true,80,0,90,30,0,0,0);
				x=300;
				y=0;
				text->Render(sprite,info,x,y);
			}break;
		case 2:
			{
				//image=GetImage(d3ddv,L"Info.png");
				text= new CSprite(true,170,0,100,30,0,0,0);
				x=500;
				y=0;
				text->Render(sprite,info,x,y);
			}break;
		case 3:
			{
				//image=GetImage(d3ddv,L"loadgame.png");
				text= new CSprite(true,0,0,200,20,0,0,0);
				x=240;
				y=230;
				text->Render(sprite,load,x,y);
			}break;
		case 4:
			{
				//image=GetImage(d3ddv,L"1player.png");
				text= new CSprite(true,0,0,200,20,0,0,0);
				x=240;
				y=200;
				text->Render(sprite,player,x,y);
			}break;
		case 5:
			{
				//image=GetImage(d3ddv,L"2player.png");
				text= new CSprite(true,0,0,200,20,0,0,0);
				x=240;
				y=260;
				text->Render(sprite,exit,x,y);
			}break;
		
	}
		
	}
}